package org.ws.lifebacklog.util;

import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

/**
 * @author sergey.valuy
 */
public class AnimationUtils {

	public static final int DEFAULT_ANIMATION_DURATION = 300;

	private AnimationUtils() {
	}

	public static Animation getSlideAnimation(float fromY) {
		return getSlideAnimation(DEFAULT_ANIMATION_DURATION, fromY);
	}

	public static Animation getSlideAnimation(int duration, float fromY) {
		Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
				0.0f, Animation.RELATIVE_TO_SELF, fromY, Animation.RELATIVE_TO_SELF, 0.0f);
		animation.setDuration(duration);
		return animation;
	}

	public static Animation getFadeInAnimation() {
		return getAlphaAnimation(DEFAULT_ANIMATION_DURATION, 1.0f, 0.0f);
	}

	public static Animation getFadeOutAnimation() {
		return getAlphaAnimation(DEFAULT_ANIMATION_DURATION, 0.0f, 1.0f);
	}

	public static Animation getFadeInAnimation(int duration) {
		return getAlphaAnimation(duration, 1.0f, 0.0f);
	}

	public static Animation getFadeOutAnimation(int duration) {
		return getAlphaAnimation(duration, 0.0f, 1.0f);
	}

	public static Animation getAlphaAnimation(int duration, float fromAlpha, float toAlpha) {
		Animation animation = new AlphaAnimation(fromAlpha, toAlpha);
		animation.setDuration(duration);
		return animation;
	}

	/*
	 * public static Animation getMyAnimation(View view) { return new MyScaler(0.0f, 0.0f, 0.0f, 0.0f,
	 * DEFAULT_ANIMATION_DURATION, view, true); }
	 * 
	 * public static class MyScaler extends TranslateAnimation {
	 * 
	 * private View mView;
	 * 
	 * private RelativeLayout.LayoutParams mLayoutParams;
	 * 
	 * private int mMarginBottomFromY, mMarginBottomToY;
	 * 
	 * private boolean mVanishAfter = false;
	 * 
	 * public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view, boolean vanishAfter) {
	 * super(fromX, toX, fromY, toY); setDuration(duration); mView = view; mVanishAfter = vanishAfter;
	 * 
	 * Logger.d(getClass(), "LParams : " + view.getLayoutParams().getClass().getName());
	 * 
	 * mLayoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams(); int height = mView.getHeight();
	 * mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height; mMarginBottomToY = (int) (0 -
	 * ((height * toY) + mLayoutParams.bottomMargin)) - height; }
	 * 
	 * @Override protected void applyTransformation(float interpolatedTime, Transformation t) {
	 * super.applyTransformation(interpolatedTime, t); Logger.d(getClass(), "applay transformation"); if
	 * (interpolatedTime < 1.0f) { int newMarginBottom = mMarginBottomFromY + (int) ((mMarginBottomToY -
	 * mMarginBottomFromY) * interpolatedTime); mLayoutParams.setMargins(mLayoutParams.leftMargin,
	 * mLayoutParams.topMargin, mLayoutParams.rightMargin, newMarginBottom); mView.getParent().requestLayout(); } else
	 * if (mVanishAfter) { mView.setVisibility(View.GONE); } }
	 * 
	 * }
	 */

}
